﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Pages
{
    public partial class UserPassword : PageBaseFrontend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    if (!base.IsVerified)
                    {
                        Response.Redirect(URL_INDEX);
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (base.IsVerified)
                {
                    Model.UserInfo user = base.VerifiedInfo.User;

                    string oldPwd = base.EncryptMD5(txbOldPwd.Text.Trim());
                    if (oldPwd != user.Password)
                    {
                        showMessage.InnerText = "您输入的旧密码不正确！";
                        showMessage.Visible = true;
                    }
                    else
                    {
                        user.Password = base.EncryptMD5(txbRePassword.Text.Trim());

                        //更新信息
                        if (BLL.UserInfoBLL.Instance.Update(user) == 1)
                        {
                            base.SuccessInfo = string.Format("密码修改成功，<a class='bluetxt' href={0}>点此退出并重新登录</a>以确认您的的新密码", "/Logout.aspx");
                            Response.Redirect(URL_INDEX);
                        }
                        else
                        {
                            showMessage.InnerHtml = "密码修改失败！";
                        }
                    }
                }
                else
                {
                    Response.Redirect(URL_LOGIN);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}